package com.zjtobacco.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjtobacco.dao.BaseDao;
import com.zjtobacco.dao.WarehouseDao;
import com.zjtobacco.domain.Warehouse;
import com.zjtobacco.service.WarehouseService;
@Service
public class WarehouseServiceImpl extends BaseServiceImpl<Warehouse, Integer>
		implements WarehouseService {

	@Autowired
	private WarehouseDao warehouseDao;
	@Override
	public BaseDao<Warehouse, Integer> getDao() {
		return warehouseDao;
	}

	
	@Override
	public void fillDetail(Warehouse warehouse) throws Exception {
		Warehouse warehouseCapacity = getCapacityById(warehouse.getId());
		if(warehouseCapacity==null){
			warehouse.setLevelCommonCapacity(0);
			warehouse.setLevelCoreCapacity(0);
			warehouse.setLevelRelatedCapacity(0);
			return;
		}
		warehouse.setLevelCoreCapacity(warehouseCapacity.getLevelCoreCapacity()!=null?warehouseCapacity.getLevelCoreCapacity():0);
		warehouse.setLevelRelatedCapacity(warehouseCapacity.getLevelRelatedCapacity()!=null?warehouseCapacity.getLevelRelatedCapacity():0);
		warehouse.setLevelCommonCapacity(warehouseCapacity.getLevelCommonCapacity()!=null?warehouseCapacity.getLevelCommonCapacity():0);
	}

	@Override
	public Warehouse getCapacityById(Integer id) throws Exception{
		return warehouseDao.getCapacityById(id);
	}

}
